import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    n1: 0,
    n2: 0
  },
  mutations: {
    addN1 (state, obj) {
      state.n1 = state.n1 + obj.n
    },
    addN2ByCalled (state, obj) {
      state.n2 = state.n2 + obj.n
    }
  },
  actions: {
    addN2 (context, obj) {
      context.state.n2 = context.state.n2 + obj.n
    },
    addN2ByCallCommit (context, obj) {
      context.commit('addN2ByCalled', obj)
    }
  },
  getters: {
    sum: state => state.n1 + state.n2
  },
  modules: {
  }
})
